package cn.qqncn.furniture.controller;

import cn.qqncn.furniture.pojo.domain.Category;
import cn.qqncn.furniture.service.CategoryService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.*;


import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * @author zkw
 * @ClassName CategoryController.java
 * @Description 商品类别控制层
 * @createTime 2020年12月13日 01:15:00
 */
@Controller
@CrossOrigin
@RequestMapping("/category")
public class CategoryController {
    @Resource
    CategoryService categoryService;

    ObjectMapper objectMapper = new ObjectMapper();

//    @RequestMapping("/getAll")
//    @ResponseBody
//    public String getAll() throws JsonProcessingException {
//        List<Category> all = categoryService.getAll();
//        return objectMapper.writeValueAsString(all);
//    }

    /**
     * 查询类别列表
     * @return
     */
    @GetMapping("getAll")
    @ResponseBody
    public String resultSet() throws JsonProcessingException {
        List<Category> list = categoryService.getAll();
        HashMap<String,Object> map1 = new HashMap<>();
        map1.put("code",0);
        map1.put("msg","success");
        map1.put("count",list.size());
        map1.put("data",list);
        return objectMapper.writeValueAsString(map1);
    }

}
